﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Program15._2_GDI
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnLine_Click(object sender, EventArgs e)
        {
            //创建GD对象
            Graphics g = this.CreateGraphics();

            //创建画笔对象
            Pen pen = new Pen(Color.Crimson, 4.0F);
            //pen.DashStyle = DashStyle.Dot;
            float[] dashValues = { 5, 2, 15, 4 };
            pen.DashPattern = dashValues;

            //画直线，建立坐标
            Point p1 = new Point(30,50);
            Point p2 = new Point(300,50);

            g.DrawLine(pen, p1, p2);
        }

        private void btnRect_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Pen pen = new Pen(Brushes.BlueViolet);

            //定义矩形大小
            Size size = new Size(100, 80);
            //定义开始坐标
            Point startpoint = new Point(30, 60);
            //定义矩形
            Rectangle rect = new Rectangle(startpoint, size);

            g.DrawRectangle(pen,rect);
        }

        private void btnCircle_Click(object sender, EventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();
            Pen pen = new Pen(Brushes.Coral,6.0F);
            g.DrawEllipse(pen, 90, 90, 200, 200);


        }

        private void btnPie_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            SolidBrush bush = new SolidBrush(Color.Crimson);
            g.FillPie(bush, 50, 100, 200, 200, 45, 90);

            Color myColor = Color.FromArgb(255, 60, 200, 100);
            bush = new SolidBrush(myColor);
            g.FillPie(bush, 50, 100, 200, 200, 135, 20);

            //写字
            g.DrawString("年度业绩", new Font("微软雅黑", 14, FontStyle.Regular), Brushes.Black, new PointF(40, 350));
        }

        private int i = 0;

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            i++;
            lblCount.Text = i.ToString();
        }

        private void label1_Click(object sender, EventArgs e)
        {
            label1.Text = ValidateCode.CreateVCode(4);

            //把图片读入内存
            MemoryStream ms = new MemoryStream();
            ms.Write(ValidateCode.CreateVCodePictre(label1.Text), 0, ValidateCode.CreateVCodePictre(label1.Text).Length);
            //显示图片的文件流格式
            pb_vCode1.Image = Image.FromStream(ms);
        }




        //当窗体绘图时触发

    }
}
